var msgTypeStore=new Ext.data.JsonStore({
	data:[
	{text:"所有类型",value:'0'},
	{text:"钻石资料",value:'1'},
	{text:"最新动态",value:'2'}],
	fields:['text','value']
});
var addMsgTypeStore=new Ext.data.JsonStore({
	data:[
	{text:"钻石资料",value:'1'},
	{text:"最新动态",value:'2'}],
	fields:['text','value']
})
var messageFormConfig={
	xtype:'form',
        width: 600,
        padding: '0 20px 0 20px',
        id: 'postMessageForm',
        frame: true,
		autoDestroy:false,
		defaults: {
				anchor: "95%",
				xtype: "textfield",
				invalidText:'该输入项不能为空!',
				allowBlank: false
        },
		items:[{
				xtype:'hidden',
				name:'messageId',
				id:'messageId'
	        },{
	            fieldLabel: "标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题",
				name:'name',
				invalidText:'验证失败',
				emptyText : '请填写标题',
				id:'name'
	        },{
	            fieldLabel: "消息类型",
				name:'msgType',
				xtype:'combo',
				editable : false,
				mode:"local",
				triggerAction : 'all',
				displayField : 'text',
				valueField : 'value',
				value:'1',
				store:addMsgTypeStore,
				invalidText:'验证失败',
				emptyText : '请选择类型',
				id:'msgType_fl'
	        },{
				xtype:'htmleditor',
	            fieldLabel: "消息内容",
				name:'content',
				allowBlank: false,
				invalidText:'验证失败',
				emptyText : '消息内容',
				id:'content'
	        }]
}

var addMessageWindowConfig={
    title: "发布消息",
	width:600,
	modal :true,
	id:'postMessageWindow',
	autoDestroy:false,
	resizable :false,
    closable: false,
    buttons: [{
        text: "提交",
    	handler: function(bt,e){
			var parent = bt.ownerCt.ownerCt;
    		saveOrUpdateMessage();
			parent.destroy();
		}
    }, {
        text: "重置",
		handler:function(bt,e){
			var parent = bt.ownerCt.ownerCt;
			var form=parent.findByType('form')
			if (Ext.isArray(form)) {
				Ext.each(form,function(f){
					f.getForm().reset();
				})
				
			}
		}
    }, {
        text: "返回",
        handler: function(bt, e){
            var parent = bt.ownerCt.ownerCt;
            parent.destroy();
        }
    }]
}

var updateMessageWindowConfig={
    title: "修改消息",
	width:600,
	modal :true,
	id:'updateMessageWindow',
	autoDestroy:false,
	resizable :false,
    closable: false,
    buttons: [{
        text: "修改",
		handler: function(bt,e){
			var parent = bt.ownerCt.ownerCt;
			saveOrUpdateMessage();
			parent.destroy();
		}
    }, {
        text: "关闭",
        handler: function(bt, e){
            var parent = bt.ownerCt.ownerCt;
			var form=parent.findByType('form')
			if(Ext.isObject(form))
				form.getForm().reset();
            parent.destroy();
        }
    }]
}

function saveOrUpdateMessage() {
	var data = {};
	data.messageId = Ext.getCmp('messageId').getValue();
	data.name = Ext.getCmp('name').getValue();
	data.msgType = Ext.getCmp('msgType_fl').getValue();
	data.content = Ext.getCmp('content').getValue();

	var con = new connection({
		url : 'addOrUpdateMessage.action',
		params : {
			json : Ext.encode(data)
		},
		success : function(rep, opt) {
			searchMessageInfo();
			var alt = rep.success ? '成功' : '失败';
			Ext.Msg.alert(alt, rep.msg);
		},
		failure : function(form, action) {
			var alt = rep.success ? '成功' : '失败';
			Ext.Msg.alert(alt, rep.msg);
		}
	})
	con.submit();
}

